package h0730;

import java.util.Scanner;
/**
  * @description 游戏分组
  * @author 不知名帅哥
  * @date 2024/7/30 22:21
  * @version 1.0
*/
public class GameGroup3 {

    private static int[] scores = new int[10];
    private static int minDifference = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // 输入10个评分
        for (int i = 0; i < 10; i++) {
            scores[i] = scanner.nextInt();
        }
        
        // 计算总和
        int totalSum = 0;
        for (int score : scores) {
            totalSum += score;
        }

        // 递归查找
        findCombination(0, 0, 0, totalSum);

        // 输出最小差值
        System.out.println(minDifference);
    }

    private static void findCombination(int index, int count, int currentSum, int totalSum) {
        // 如果选择了5个选手
        if (count == 5) {
            int otherSum = totalSum - currentSum;
            int difference = Math.abs(currentSum - otherSum);
            minDifference = Math.min(minDifference, difference);
            return;
        }

        // 如果到达数组末尾或选择的选手已满
        if (index >= 10) {
            return;
        }

        // 选择当前选手
        findCombination(index + 1, count + 1, currentSum + scores[index], totalSum);
        // 不选择当前选手
        findCombination(index + 1, count, currentSum, totalSum);
    }
}
